import {
  handleError,
  ref
} from 'vue'
import {
  useMusicStore
} from '@/store/modules/musicStore.js'
const musicStore = useMusicStore()
const innerAudioContext = uni.createInnerAudioContext()
innerAudioContext.autoplay = true
const currentTime = ref(0)
const duration = ref(0)
export default {
  playAudio(src) {
    innerAudioContext.src = src
  },
  duration() {
    duration.value = innerAudioContext.duration
    return currentTime.value
  },
  currentTime() {
    currentTime.value = innerAudioContext.currentTime
    return currentTime.value
  },
  seek(currentTime) {
    console.log('进入时间', currentTime);
    innerAudioContext.seek(currentTime)
  },
  play() {
    innerAudioContext.play()
  },
  pause() {
    innerAudioContext.pause()
  },
  onPlay(handlePlay) {
    innerAudioContext.onPlay(handlePlay)
  },
  onError(handleError) {
    innerAudioContext.onError(handleError)
  },
  onTimeUpdate(handleTimeUpdate) {
    innerAudioContext.onTimeUpdate(handleTimeUpdate)
  },
  onStop(handleStop) {
    innerAudioContext.onStop(handleStop)
  },
  onEnded(handleEnded) {
    innerAudioContext.onEnded(handleEnded)
  },
  onCanplay(handleCanplay) {
    innerAudioContext.onCanplay(handleCanplay)
  },
  offPlay() {
    innerAudioContext.offPlay()
  },
  offError() {
    innerAudioContext.offError()
  },
  offTimeUpdate() {
    innerAudioContext.offTimeUpdate()
  },
  offStop() {
    innerAudioContext.offStop()
  },
  offEnded() {
    innerAudioContext.offEnded()
  },
  destroy() {
    innerAudioContext.destroy()
  },
}